import java.sql.*;

public class JDBCTEST {

        public static void main(String[] args) throws SQLException, ClassNotFoundException {
            String dbUrl = "jdbc:mysql://localhost:3306/bookstore";
            String dbUser = "root";
            String dbPass = "1911lzrnb";
            Class.forName("com.mysql.cj.jdbc.Driver");
            try (Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPass)) {
                try (Statement statement = connection.createStatement()) {
                    String sql = "select id,name,author,price from book";
                        try(ResultSet resultSet = statement.executeQuery(sql) ){
                            while (resultSet.next()) {
                            int id = resultSet.getInt("id");
                            String name = resultSet.getString("name");
                            String author = resultSet.getString("Author");
                            float price = resultSet.getFloat("price");

                            System.out.println(String.format("%s, %s, %s, %s", id, name, author, price));
                        }
                    }
                }
            }
        }
}

